package com.blrs.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.blrs.common.annotation.RepeatSubmit;
import com.blrs.common.core.page.PageDomain;
import com.blrs.common.core.page.TableSupport;
import com.blrs.common.utils.SecurityUtils;
import com.blrs.common.utils.page.PaginationUtil;
import com.blrs.domain.EnterpriseInfo;
import com.blrs.domain.InternalDocument;
import com.blrs.domain.MainType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.domain.FileCabinetInformation;
import com.blrs.service.file.IFileCabinetInformationService;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 文件柜维护Controller
 * 
 * @author ruoyi
 * @date 2023-11-01
 */
@RestController
@RequestMapping("/file/information")
public class FileCabinetInformationController extends BaseController
{
    @Autowired
    private IFileCabinetInformationService fileCabinetInformationService;



    @GetMapping("/listPermission")
    public TableDataInfo listPermission(FileCabinetInformation fileCabinetInformation)
    {
        startPage();
        List<FileCabinetInformation> list = fileCabinetInformationService.selectExternalDocumentPermissionList(fileCabinetInformation);
        return getDataTable(list);
    }

    /**
     * 查询文件柜树形列表
     */
    @GetMapping("/listFileTree")
    public AjaxResult listFileTree(FileCabinetInformation fileCabinetInformation)
    {
        /*Long userid = SecurityUtils.getUserId();
        if(userid!=1){

        }*/
        fileCabinetInformation.setBelongTo(SecurityUtils.getOrgId());
        List<Map> list = fileCabinetInformationService.getFileTree(fileCabinetInformation);
        return success(list);
    }

    /**
     * 查询文件柜维护列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FileCabinetInformation fileCabinetInformation)
    {
        startPage();
       /* Long userid = SecurityUtils.getUserId();

        if(userid!=1){

        }*/
        //暂存
        fileCabinetInformation.setOperateName("1");
        fileCabinetInformation.setBelongTo(SecurityUtils.getOrgId());
        List<FileCabinetInformation> list = fileCabinetInformationService.selectFileCabinetInformationList(fileCabinetInformation);
        return getDataTable(list);
    }

    /**
     * 导出文件柜维护列表
     */

    @Log(title = "文件柜维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FileCabinetInformation fileCabinetInformation)
    {
        List<FileCabinetInformation> list = fileCabinetInformationService.selectFileCabinetInformationList(fileCabinetInformation);
        ExcelUtil<FileCabinetInformation> util = new ExcelUtil<FileCabinetInformation>(FileCabinetInformation.class);
        util.exportExcel(response, list, "文件柜维护数据");
    }

    /**
     * 获取文件柜维护详细信息
     */

    @GetMapping(value = "/{cabinetId}")
    public AjaxResult getInfo(@PathVariable("cabinetId") String cabinetId)
    {
        return success(fileCabinetInformationService.selectFileCabinetInformationByCabinetId(cabinetId));
    }

    /**
     * 新增文件柜维护
     */

    @Log(title = "文件柜维护", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit(interval = 1000,message = "请勿重复提交！")
    public AjaxResult add(@RequestBody FileCabinetInformation fileCabinetInformation)
    {
        return toAjax(fileCabinetInformationService.insertFileCabinetInformation(fileCabinetInformation));
    }

    /**
     * 修改文件柜维护
     */

    @Log(title = "文件柜维护", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit(interval = 1000,message = "请勿重复提交！")
    public AjaxResult edit(@RequestBody FileCabinetInformation fileCabinetInformation)
    {
        return toAjax(fileCabinetInformationService.updateFileCabinetInformation(fileCabinetInformation));
    }

    /**
     * 删除文件柜维护
     */

    @Log(title = "文件柜维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cabinetId}")
    public AjaxResult remove(@PathVariable String cabinetId)
    {
        return toAjax(fileCabinetInformationService.deleteFileCabinetInformationByCabinetId(cabinetId));
    }
}
